#include "Block.h"
#include "Utility.h"

static const int DEFAULT_CAPACITY_BASE = 4096;

Block::Block(int size)
{
    _size = checkedAlign(size);
    _data = new unsigned char[_size](); 
}

Block::Block(unsigned char c, int capacity, int repeat)
: Block(checkedAlign(capacity))
{
    if (repeat > _size) {
        repeat = _size;
    }

    for(int i = 0; i < repeat; ++i) {
        _data[i] = c;
    }
}

Block::~Block() {
    delete [] _data;
    _data = nullptr;
    _size = 0;
}

int Block::size() const {
    return _size;
}

unsigned char * Block::data() {
    return _data;
}

int Block::checkedAlign(int size) {
    return BitUtility::alignGreaterEqual(size, DEFAULT_CAPACITY_BASE);
}

